var deviceone = require("deviceone");
var app = deviceone.sm("do_App");
var page = deviceone.sm("do_Page");
var hashdata = deviceone.mm("do_HashData");
var nf = deviceone.sm("do_Notification");
var cacher = deviceone.sm("do_DataCache");
var qRCode = deviceone.sm("do_QRCode");

var imageViewImg=ui("imageViewImg");
var labelName=ui("labelName");
var labelDesc=ui("labelDesc");
var preData = page.getData();
var bizzType = preData.bizzType;
var bizzId = preData.bizzId;
var img = preData.img;
var name = preData.name;
var desc = preData.desc;
imageViewImg.source=img;
labelName.text=name;
labelDesc.text=desc;

var title = "二维码图片";
if(bizzType==="A"){
	title = "我的二维码";
}else if(bizzType==="B"){
	title = "圈子二维码";
}else if(bizzType==="C"){
	title = "社区二维码";
}
page.on("back", function() {
	app.closePage();
});
page.on("loaded", function() {
	/** 二维码缓存的key，后面要跟业务类型+id，如QRCode-A-1 **/
	var mapKey_qrCode = "QRCode-"+bizzType+"-"+bizzId;
	var paramsStr = "http://a.app.qq.com/o/simple.jsp?pkgname=com.qqtech.qquan.product"+"&bizzType="+bizzType+"&bizzId="+bizzId;
	if(cacher.hasData(mapKey_qrCode)){
		var imgUrl = cacher.loadData(mapKey_qrCode);
		if(!imgUrl || imgUrl==null || imgUrl==="undefined"){
			ui("do_ImageView_qrCode").source = imgUrl;
		}else{
			qRCode.create(paramsStr,function(data,e){
				ui("do_ImageView_qrCode").source = data;
				cacher.removeData(mapKey_qrCode);
				cacher.saveData(mapKey_qrCode,data);
			});
		}
	}else{
		qRCode.create(paramsStr,function(data,e){
			ui("do_ImageView_qrCode").source = data;
			cacher.saveData(mapKey_qrCode,data);
		});
	}
});
var layoutHead = ui("layoutHead");
var addheader = layoutHead.add("header", "source://view/reuse/header.ui", 0, 0);
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
  app.closePage()
});
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
  "labelTitle" : title
});
header.refreshData();